package org.qengine.entity;


import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

@Data
@TableName("papers") // 表名
public class PapersEntity {
    @TableId
    private Long paperId;// 主键
    private String questionIds; // 试题ID列表
    private LocalDateTime createTime;
    private Long ruleId;
    private String type;
    public Long[] getQuestionIdsAsArray() {
        if (this.questionIds == null || this.questionIds.isEmpty()) {
            return new Long[0]; // 如果字符串为空，返回空数组
        }
        String[] ids = this.questionIds.split(","); // 按逗号分割字符串
        Long[] longIds = new Long[ids.length];
        for (int i = 0; i < ids.length; i++) {
            longIds[i] = Long.parseLong(ids[i].trim()); // 将每个字符串转换为 Long
        }
        return longIds;
    }
    public void setQuestionIdsFromArray(Long[] questionIdsArray) {
        if (questionIdsArray == null || questionIdsArray.length == 0) {
            this.questionIds = ""; // 如果数组为空，设置为空字符串
            return;
        }
        StringBuilder sb = new StringBuilder();
        for (Long id : questionIdsArray) {
            sb.append(id).append(","); // 将每个 Long 值拼接为字符串
        }
        sb.deleteCharAt(sb.length() - 1); // 删除最后一个多余的逗号
        this.questionIds = sb.toString();
    }
}



